home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2005 June (DVD) / DPPRO0605DVD.iso / Install / program files / Borland / BDS / 3.0 / Demos / Delphi.Net / CLR / Threading / delphiTthread.dpr < prev    next >
Encoding:
Text File  |  2004-10-22  |  1.1 KB  |  63 lines

  1. program delphiTthread;
  2. {$APPTYPE CONSOLE}
  3.  
  4. //
  5. // This example demonstrates how write a threaded application using the
  6. // TThread class. 
  7. // 
  8. // Written by: Rick Ross (http://www.rick-ross.com/)
  9. //
  10.  
  11. uses
  12.   SysUtils, Classes;
  13.  
  14. type
  15.   TThreadMe = class(TThread)
  16.   private
  17.     FStartNum: integer;
  18.   protected
  19.     procedure Execute; override;
  20.   public
  21.     property StartNum : integer write FStartNum;
  22.   end;
  23.  
  24. { TThreadMe }
  25.  
  26. procedure TThreadMe.Execute;
  27. var
  28.   stop : integer;
  29.   curNum : integer;
  30.  
  31. begin
  32.   curNum := FStartNum;
  33.   stop := FStartNum + 10;
  34.   while curNum < stop do
  35.   begin
  36.     writeln('Thread ', AppDomain.GetCurrentThreadID() ,' current value is ',curNum);
  37.     inc(curNum);
  38.     Sleep( 3 );
  39.   end;
  40. end;
  41.  
  42. var
  43.   thrd : TThreadMe;
  44.   thrd2 : TThreadMe;
  45.  
  46. begin
  47.   writeln('Staring TThread example...');
  48.  
  49.   // create TThreadMe instance
  50.   thrd := TThreadMe.create(false);
  51.   thrd.StartNum := 10;
  52.  
  53.   thrd2 := TThreadMe.create(false);
  54.   thrd2.StartNum := 100;
  55.  
  56.   thrd.Resume;
  57.   thrd2.Resume;
  58.  
  59.   readln;
  60.   writeln('Done');
  61. end.
  62.  
  63.